#ifndef GPSREADER_H
#define GPSREADER_H

#include <QObject>
#include <QStringList>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QDebug>
#include <string.h>
#include <QTimer>
#include <QFile>
#include <QStringList>
#include "recordconfig.h"
#include 	<stdio.h>
#include 	<stdlib.h>
#include 	<string.h>
#include 	<stdarg.h>
#include 	<errno.h>
#include 	<math.h>
#include 	<sys/types.h>
#include 	<netinet/in.h>
#include 	<sys/socket.h>
#include 	<sys/wait.h>
#include 	<unistd.h>
#include 	<arpa/inet.h>
#include 	<sys/mman.h>
#include 	<syscall.h>
#include 	<fcntl.h>
#include 	<sys/epoll.h>
#include 	<sys/time.h>
#include 	<sys/resource.h>
#include 	<pthread.h>
#include 	<sys/stat.h>
#include 	<locale.h>
#include 	<semaphore.h>
#include 	<signal.h>
#include 	<setjmp.h>
#include 	<time.h>
#include 	<limits.h>
#include 	<ctype.h>
#include 	<float.h>
#include 	<stddef.h>
#include	<netdb.h>
#include 	<assert.h>
#include	<termios.h>

class GpsReader : public QObject
{
    Q_OBJECT
public:
    explicit GpsReader(QObject *parent = 0);
    void recordStart();
    void testRtkState(bool state);

private:
    QSerialPort comGps;
    RecordConfig* recConfig;
    QByteArray dataCache;
    QString devName;
    QStringList devList;
    QTimer testTimer;
    QFile* testFile;
    bool rtkFlag;
    quint64 posNum;
    bool waitforGpgga;
    double last_lat;
    double last_lon;
    int total;

    void initDevice();

    int DataProcess(char *buf, int len);
    int kmp(const char *Text, const char *Pattern);
    int RtkSet(char *path);
    int IsEqual(double a, double b);
    int get_nextval(const char *T, int next[]);
    void WGS84ToGuass(double latitude, double longitude, double *x, double *y);
    void readDataCache();
    int rtkSet(char *path);
    int getGpgga(int gfd, char *gpgga);
    int setQianxun(char *buffer, char *path);
    int ComInit(char *DevPath, speed_t baud);
    int _write(int fd, void *buffer, int length);
signals:
    void rtkState(bool);
    void newPos(double, double, QString, QString, QString, QString);//x坐标-y坐标-偏航角-速度-纬度-经度

public slots:

private slots:
    void readGpsData();
    void testTimeout();
};

#endif // GPSREADER_H
